<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML5 Geolocation定位</title>
</head>
<body>
    <h1>HTML5 Geolocation定位</h1>
    <div class="position"></div>
    <script>
        const options = {
            enableHighAccuracy: true,
            timeout: 10000,
            maximumAge: 0
        };

        const position = document.querySelector('.position')

        navigator.geolocation.getCurrentPosition((pos)=>{
            console.log('pos',pos)
            position.innerHTML = JSON.stringify(pos.coords)
        },(err)=>{
            console.error(err);
            // throw new Error('xxxx')
        },options)
    </script>
</body>
</html>